<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let p = new Promise((resolve, reject) =>{
            resolve('succeed')
            // reject('eror')
        }) 
        // 每一个promise对象都会有一个then方法 ，then方法里会接收2种回调 ，onResolved 和 onRejected
        // onResolved  :成功状态的promise 会执行 onResolved回调函数
        // onRejected : 失败状态的 promise 会执行 onRejected回调函数
        // 可以把 onRejected 省略掉 
        // let p1 = p.then((res) => {
        //     console.log(res);
        // },(err) => {
        //     console.log(err);
        // })
        // console.log(p1);

        // 1.没有返还: 得到成功状态的promise 对象 promiseResult 是undefined 
        let thenResult = p.then(res => {
            console.log(res);
        })
        console.log(thenResult);

        let thenResult1 = p.then(res => {
            console.log(res);
            return '手写返回值'
        })
        console.log(thenResult1);

        let thenResult2 = p.then(res => {
            console.log(res);
            return new Promise(resolve =>{
                resolve('succeed2');
            });
        })
        console.log(thenResult2);

        let thenResult3 = p.then(res => {
            console.log(res);
            throw Error("错了");
        })
        console.log(thenResult3);

        // 总结：无论如何 ，promise的then方法 都会返还一个promise对象。每个promise对象都会有一个then方法.then 是可以无限链式调用
        let p2 = p.then(res => {
            return '111'
        })
        let p3 = p2.then(res => {
            console.log(res);
        })
        let p4 = p3.then(res => {
            console.log(undefined);
        })
    
    
    
    </script>
</body>
</html>